//
//  XTXxingaiziliaoViewController.m
//  XZ_WeChat
//
//  Created by 余清巍 on 2017/9/7.
//  Copyright © 2017年 gxz. All rights reserved.
//
//编辑资料
#import "XTXxingaiziliaoViewController.h"
#import "SDAutoLayout.h"
#import "UIImageView+WebCache.h"
#import "XTXgexingqianmingViewController.h"
#import "XTXEditCell.h"
#import "XTXEditCell1.h"
#import "XTXTool.h"
#import <AVFoundation/AVFoundation.h>
#import <ifaddrs.h>
#import <arpa/inet.h>
#import "XTXDengluViewController.h"
@interface XTXxingaiziliaoViewController ()<UICollectionViewDelegate,UICollectionViewDataSource,UITextFieldDelegate,UIImagePickerControllerDelegate,UINavigationControllerDelegate>{
    NSString *xianshishengrizifuchuang;//显示用的生日
    NSString *shangchuangshengrizifuchuang;//上传用的生日
    NSInteger limitInteger;
    CGFloat  tupiandaxiao;//图片大小
    UIView *bgView;
    NSString *currentDate;
}
@property (nonatomic,strong)UICollectionView *collectionViewClass;//选择类别
@property (nonatomic, strong) XTXEditCell1 *cell1;
@property (nonatomic,strong)UICollectionView *classificationView;//类别
@property (nonatomic, strong) XTXEditCell *cell;
@property (nonatomic,strong) UIView *touxiangbeijingView;//头像背景
@property (nonatomic,strong) UIImageView *touxiangImageView;//头像
@property (nonatomic,strong) UILabel *xiugaitouxiangLabel;//修改头像
@property (nonatomic,strong) UIImageView *tuozhanfuImageView;//扩展符
@property (nonatomic,strong) UIView *nichengbeijingView;//昵称背景
@property (nonatomic,strong) UIView *fengexian01;//分割线
@property (nonatomic,strong) UIView *shengribeijingView;//生日背景
@property (nonatomic,strong) UILabel *nichenLabel;//昵称
@property (nonatomic,strong) UIImageView *tuozhanfuImageView02;//扩展符
@property (nonatomic,strong) UILabel *shengriLabel;//生日
@property (nonatomic,strong) UIImageView *tuozhanfuImageView03;//扩展符
@property (nonatomic,strong) UITextField *yonghumingTextField;//用户名输入框
@property (nonatomic,strong) UILabel *yonghushengriLabel;//用户生日
@property (nonatomic,strong) UIView *fengexian02;//分割线
@property (nonatomic,strong) UIImageView *tuozhanfuImageView04;//扩展符
@property (nonatomic,strong) UIView *gexingbiaoqianbgView;//个性标签背景
@property (nonatomic,strong) UILabel *quxuanzeLabel;//去选择
@property (nonatomic,strong) UIImageView *tuozhanfuImageView05;//扩展符
@property (nonatomic,strong) UIView *fengexian03;//分割线
@property (nonatomic,strong) UILabel *gexingbiaoqianLabel;//个性标签
@property (nonatomic,strong) UIView *gexingqianmingBgView;//个性签名背景
@property (nonatomic,strong) UILabel *gexingqianmingxtxLabel;//个性签名
@property (nonatomic,strong) UILabel *gexingqianmingcontentLabel;//个性签名内容
@property (nonatomic,strong) UIImageView *tuozhanfuImageView06;//扩展符
@property (nonatomic,assign) CGSize gexingqianmingSize;//计算个性签名
@property (nonatomic,strong) UIDatePicker *picker;//生日选择
@property (nonatomic,strong) UIView *shengribgxuanzeView;//生日选择背景
@property (nonatomic,strong) UIView * bgGexingbiaoqianbgview;//个性标签背景
@property (nonatomic,strong) NSArray *arr;
@property (nonatomic,strong) NSMutableArray *selectedGexingbiaoqianMArr;//选择的个性标签
@property (nonatomic, strong) UIImagePickerController *iconXuanzePickerController;
@property (nonatomic, strong) NSData *wenjianShuju;
@property (nonatomic, strong) MBProgressHUD *juhuazhuanHud;
@property (nonatomic, strong) UIButton *cancellationBtn;

@end

@implementation XTXxingaiziliaoViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    [XTXTool share].gexingqianmingshuzipanduan =0;
    _arr=[[XTXTool share].user objectForKey:@"listLabel"];
    _selectedGexingbiaoqianMArr = [NSMutableArray array];
    [self chushihuadaohanglan];
    [self setUI];
    _gexingqianmingcontentLabel.text = [XTXTool share].ConsumerModel.autograph;
    _gexingqianmingSize = [_gexingqianmingcontentLabel sizeThatFits:CGSizeMake(_gexingqianmingcontentLabel.frame.size.width, MAXFLOAT)];
    [self bujuyueshushezhi];
    _yonghumingTextField.text = [XTXTool share].ConsumerModel.nickname;
    if ([[XTXTool share].ConsumerModel.label isEqualToString:@""]) {
        [self shotWithView:self.view];
    }else{
        [_selectedGexingbiaoqianMArr addObjectsFromArray:[[XTXTool share].ConsumerModel.label componentsSeparatedByString:@","]];
    }
    
}
-(UIImage *)shotWithView:(UIView *)view{
    UIGraphicsBeginImageContext(view.bounds.size);
    [view.layer renderInContext:UIGraphicsGetCurrentContext()];
    UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
    return image;
}


-(void)setUI{
    [self.view addSubview:self.touxiangbeijingView];
    [self.touxiangbeijingView addSubview:self.touxiangImageView];
    [self.touxiangbeijingView addSubview:self.tuozhanfuImageView];
    [self.touxiangbeijingView addSubview:self.xiugaitouxiangLabel];
    [self.view addSubview:self.nichengbeijingView];
    [self.view addSubview:self.shengribeijingView];
    [self.nichengbeijingView addSubview:self.fengexian01];
    [self.nichengbeijingView addSubview:self.nichenLabel];
    [self.shengribeijingView addSubview:self.shengriLabel];
    [self.nichengbeijingView addSubview:self.tuozhanfuImageView02];
    [self.shengribeijingView addSubview:self.tuozhanfuImageView03];
    [self.nichengbeijingView addSubview:self.yonghumingTextField];
    [self.shengribeijingView addSubview:self.yonghushengriLabel];
    [self.view addSubview:self.gexingbiaoqianbgView];
    [self.gexingbiaoqianbgView addSubview:self.tuozhanfuImageView05];
    [self.gexingbiaoqianbgView addSubview:self.quxuanzeLabel];
    [self.gexingbiaoqianbgView addSubview:self.gexingbiaoqianLabel];
    [self.gexingbiaoqianbgView addSubview:self.collectionViewClass];
    [_collectionViewClass registerNib:[UINib nibWithNibName:@"XTXEditCell1" bundle:nil] forCellWithReuseIdentifier:@"XTXEditCell1"];
    [self.gexingbiaoqianbgView addSubview:self.fengexian03];
    [self.view addSubview:self.gexingqianmingBgView];
    [self.gexingqianmingBgView addSubview:self.tuozhanfuImageView06];
    [self.gexingqianmingBgView addSubview:self.gexingqianmingxtxLabel];
    [self.gexingqianmingBgView addSubview:self.gexingqianmingcontentLabel];
    [self shengrixuanzeEventClick];//生日选择
    [self gerenClick];//个性标签选择
    [self shotWithView:self.view scope:CGRectZero];
}
-(UIImage *)shotWithView:(UIView *)view scope:(CGRect)scope{
    CGImageRef imageRef = CGImageCreateWithImageInRect([self shotWithView:view].CGImage, scope);
    UIGraphicsBeginImageContext(scope.size);
    CGContextRef context = UIGraphicsGetCurrentContext();
    CGRect rect = CGRectMake(0, 0, scope.size.width, scope.size.height);
    CGContextTranslateCTM(context, 0, rect.size.height);//下移
    CGContextScaleCTM(context, 1.0f, -1.0f);//上翻
    CGContextDrawImage(context, rect, imageRef);
    UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
    CGImageRelease(imageRef);
    CGContextRelease(context);
    return image;
}
-(void)bujuyueshushezhi{
    _touxiangbeijingView.sd_layout.topSpaceToView(self.navigationController.navigationBar, iOS_frame_height(20)).leftSpaceToView(self.view, 0).rightSpaceToView(self.view, 0).heightIs(iOS_frame_height(170));
    _touxiangImageView.sd_layout.centerYEqualToView(_touxiangbeijingView).leftSpaceToView(_touxiangbeijingView, iOS_frame_width(30)).widthIs(iOS_frame_width(110)).heightIs(iOS_frame_width(110));
    _tuozhanfuImageView.sd_layout.widthIs(iOS_frame_width(10)).heightIs(iOS_frame_height(20)).rightSpaceToView(_touxiangbeijingView, iOS_frame_width(30)).centerYEqualToView(_touxiangbeijingView);
    _xiugaitouxiangLabel.sd_layout.centerYEqualToView(_touxiangbeijingView).heightIs(iOS_frame_width(20)).widthIs(iOS_frame_width(200)).rightSpaceToView(_tuozhanfuImageView, iOS_frame_width(30));
    _nichengbeijingView.sd_layout.leftSpaceToView(self.view, 0).rightSpaceToView(self.view, 0).heightIs(iOS_frame_height(110)).topSpaceToView(self.touxiangbeijingView, iOS_frame_height(20));
    _shengribeijingView.sd_layout.rightSpaceToView(self.view, 0).leftSpaceToView(self.view, 0).heightIs(iOS_frame_height(110)).topSpaceToView(_nichengbeijingView, 0);
    _fengexian01.sd_layout.rightSpaceToView(_nichengbeijingView, 0).leftSpaceToView(_nichengbeijingView, iOS_frame_width(30)).heightIs(iOS_frame_height(1)).bottomSpaceToView(_nichengbeijingView, 0);
    _nichenLabel.sd_layout.centerYEqualToView(self.nichengbeijingView).heightIs(iOS_frame_height(30)).leftSpaceToView(self.nichengbeijingView, 30).widthIs(iOS_frame_width(100));
    _shengriLabel.sd_layout.centerYEqualToView(self.shengribeijingView).heightIs(iOS_frame_height(30)).leftSpaceToView(self.shengribeijingView, 30).widthIs(iOS_frame_width(100));
    _tuozhanfuImageView02.sd_layout.widthIs(iOS_frame_width(10)).heightIs(iOS_frame_height(20)).rightSpaceToView(_nichengbeijingView, iOS_frame_width(30)).centerYEqualToView(_nichengbeijingView);
    _tuozhanfuImageView03.sd_layout.widthIs(iOS_frame_width(10)).heightIs(iOS_frame_height(20)).rightSpaceToView(_shengribeijingView, iOS_frame_width(30)).centerYEqualToView(_shengribeijingView);
    _yonghumingTextField.sd_layout.rightSpaceToView(_tuozhanfuImageView02, iOS_frame_width(30)).leftSpaceToView(_nichenLabel, 0).heightIs(iOS_frame_height(80)).centerYEqualToView(_nichengbeijingView);
    _yonghushengriLabel.sd_layout.centerYEqualToView(_shengribeijingView).rightSpaceToView(_tuozhanfuImageView03, iOS_frame_width(30)).heightIs(iOS_frame_height(30)).leftSpaceToView(_shengriLabel, 0);
    if ([[XTXTool share].ConsumerModel.sex isEqualToString:@"1"]) {
        _gexingbiaoqianbgView.sd_layout.rightSpaceToView(self.view, 0).leftSpaceToView(self.view, 0).heightIs(iOS_frame_height(0)).topSpaceToView(_shengribeijingView , iOS_frame_height(20));
    }else{
        _gexingbiaoqianbgView.sd_layout.rightSpaceToView(self.view, 0).leftSpaceToView(self.view, 0).heightIs(iOS_frame_height(0)).topSpaceToView(_shengribeijingView, iOS_frame_height(20));
    }
    _gexingbiaoqianbgView.hidden = YES;
    _tuozhanfuImageView05.sd_layout.widthIs(iOS_frame_width(10)).heightIs(iOS_frame_height(20)).rightSpaceToView(_gexingbiaoqianbgView, iOS_frame_width(30)).centerYEqualToView(_gexingbiaoqianbgView);
    _fengexian03.sd_layout.rightSpaceToView(_gexingbiaoqianbgView, 0).leftSpaceToView(_gexingbiaoqianbgView, iOS_frame_width(30)).heightIs(iOS_frame_height(1)).bottomSpaceToView(_gexingbiaoqianbgView, 0);
    _quxuanzeLabel.sd_layout.rightSpaceToView(_tuozhanfuImageView05, iOS_frame_width(30)).heightIs(iOS_frame_height(30)).centerYEqualToView(_gexingbiaoqianbgView).widthIs(iOS_frame_width(120));
    _gexingbiaoqianLabel.sd_layout.centerYEqualToView(_gexingbiaoqianbgView).leftSpaceToView(_gexingbiaoqianbgView, iOS_frame_width(30)).heightIs(iOS_frame_height(30)).widthIs(iOS_frame_width(140));
    if (_gexingqianmingSize.height>10+_gexingqianmingcontentLabel.font.lineHeight) {
        _gexingqianmingBgView.sd_layout.leftSpaceToView(self.view, 0).rightSpaceToView(self.view, 0).heightIs(iOS_frame_height(150)).topSpaceToView(_gexingbiaoqianbgView, 0);
    }else{
        _gexingqianmingBgView.sd_layout.leftSpaceToView(self.view, 0).rightSpaceToView(self.view, 0).heightIs(iOS_frame_height(110)).topSpaceToView(_gexingbiaoqianbgView, 0);
    }
    
    _tuozhanfuImageView06.sd_layout.widthIs(iOS_frame_width(10)).heightIs(iOS_frame_height(20)).rightSpaceToView(_gexingqianmingBgView, iOS_frame_width(30)).centerYEqualToView(_gexingqianmingBgView);
    _gexingqianmingxtxLabel.sd_layout.topSpaceToView(_gexingqianmingBgView, iOS_frame_height(40)).leftSpaceToView(_gexingqianmingBgView, iOS_frame_width(30)).heightIs(iOS_frame_height(33)).widthIs(iOS_frame_width(140));
    if (_gexingqianmingSize.height>10+_gexingqianmingcontentLabel.font.lineHeight) {
        _gexingqianmingcontentLabel.textAlignment = NSTextAlignmentLeft;
    }else{
        _gexingqianmingcontentLabel.textAlignment = NSTextAlignmentRight;
    }
    _gexingqianmingcontentLabel.sd_layout.rightSpaceToView(_gexingqianmingBgView, iOS_frame_width(60)).leftSpaceToView(_gexingqianmingBgView, iOS_frame_width(190)).topSpaceToView(_gexingqianmingBgView, iOS_frame_height(40)).heightIs(_gexingqianmingSize.height);
    [self compressOriginalImage:imageNamed(@"iconImage2") toSize:CGSizeMake(0, 0)];
    [self.view addSubview:self.cancellationBtn];
    [self.cancellationBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.gexingqianmingxtxLabel.mas_left);
        make.right.equalTo(self.tuozhanfuImageView.mas_right);
        make.height.offset(44);
        if (@available(iOS 11.0, *)) {
            make.bottom.equalTo(self.view.mas_safeAreaLayoutGuideBottom).offset(-80);
        } else {
            make.bottom.equalTo(self.view.mas_bottom).offset(-80);
        }
    }];
}
-(UIImage *)compressOriginalImage:(UIImage *)image toSize:(CGSize)size{
    UIImage *resultImage = image;
    UIGraphicsBeginImageContext(size);
    [resultImage drawInRect:CGRectMake(0, 0, size.width, size.height)];
    UIGraphicsEndImageContext();
    return resultImage;
}

-(void)shengrixuanzeEventClick{
    _shengribgxuanzeView = [[UIView alloc]initWithFrame:CGRectMake(0, APP_Frame_Height, App_Frame_Width, iOS_frame_height(500))];
    _shengribgxuanzeView.backgroundColor = [UIColor whiteColor];
    [[[UIApplication  sharedApplication]keyWindow] addSubview:_shengribgxuanzeView];
    NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
    [dateFormatter setDateFormat:@"dd-MM-yyyy"];
    NSDate *maxDate = [dateFormatter dateFromString:@"01-01-1998"];
    NSDate *minDate = [dateFormatter dateFromString:@"01-01-1950"];
    _picker = [[UIDatePicker alloc]initWithFrame:CGRectMake(0, iOS_frame_height(80), App_Frame_Width, iOS_frame_height(420))];
    self.picker.backgroundColor = XZColor(250,250,250);
    [self.picker setDate:[dateFormatter dateFromString:@"01-01-1990"] animated:YES];//设置默认日期
    self.picker.datePickerMode = UIDatePickerModeDate;
    self.picker.minuteInterval = 10;
    self.picker.minimumDate = minDate;//设置显示的最小日期
    self.picker.maximumDate = maxDate;//设置显示的最大日期
    [self.picker setTintColor:[UIColor redColor]];//设置主色
    [self.picker addTarget:self action:@selector(dateChanged:) forControlEvents:UIControlEventValueChanged];
    [_shengribgxuanzeView addSubview:self.picker];
    UIView *lineview = [[UIView alloc]initWithFrame:CGRectMake(0, iOS_frame_height(80), App_Frame_Width, 1)];
    lineview.backgroundColor = XZColor(231,231,231);
    [_shengribgxuanzeView addSubview:lineview];
    UIButton * cancel = [UIButton buttonWithType:UIButtonTypeCustom];
    [cancel setTitle:@"取消" forState:(UIControlStateNormal)];
    cancel.titleLabel.font = [UIFont systemFontOfSize:iOS_frame_width(30)];
    [cancel addTarget:self action:@selector(quxiaoshengrixuanzeEvent)forControlEvents:UIControlEventTouchUpInside];
    [cancel setTitleColor:XZColor(105,105,105) forState:UIControlStateNormal];
    cancel.frame = CGRectMake(iOS_frame_width(50), 0, iOS_frame_width(80), iOS_frame_height(79));
    [_shengribgxuanzeView addSubview:cancel];
    UIButton * determine = [UIButton buttonWithType:UIButtonTypeCustom];
    [determine setTitle:@"确定" forState:(UIControlStateNormal)];
    determine.titleLabel.font = [UIFont systemFontOfSize: iOS_frame_width(30)];
    [determine addTarget:self action:@selector(shengrixuanzequedinganniuClickEvent)forControlEvents:UIControlEventTouchUpInside];
    [determine setTitleColor:XZColor(105,105,105) forState:UIControlStateNormal];
    determine.frame = CGRectMake(iOS_frame_width(620), 0, iOS_frame_width(80), iOS_frame_height(79));
    [_shengribgxuanzeView addSubview:determine];
    UILabel *Choosebirthday = [UILabel new];
    Choosebirthday.text = @"生日选择";
    Choosebirthday.textColor = [UIColor blackColor];
    Choosebirthday.textAlignment = NSTextAlignmentCenter;
    [_shengribgxuanzeView addSubview:Choosebirthday];
    Choosebirthday.sd_layout.topSpaceToView(_shengribgxuanzeView, 0).centerXEqualToView(_shengribgxuanzeView).widthIs(iOS_frame_width(300)).heightIs(iOS_frame_height(80));
    [self compressOriginalImage:imageNamed(@"iconImage3") toMaxDataSizeKBytes:0];
}
-(NSData *)compressOriginalImage:(UIImage *)image toMaxDataSizeKBytes:(CGFloat)size{
    NSData *data = UIImageJPEGRepresentation(image, 1.0);
    CGFloat dataKBytes = data.length/1000.0;
    CGFloat maxQuality = 0.9f;
    CGFloat lastData = dataKBytes;
    while (dataKBytes > size && maxQuality > 0.01f) {
        maxQuality = maxQuality - 0.01f;
        data = UIImageJPEGRepresentation(image, maxQuality);
        dataKBytes = data.length/1000.0;
        if (lastData == dataKBytes) {
            break;
        }else{
            lastData = dataKBytes;
        }
    }
    return data;
}
-(void)gerenClick{
    _bgGexingbiaoqianbgview = [[UIView alloc]initWithFrame:CGRectMake(0, APP_Frame_Height, App_Frame_Width, iOS_frame_height(500))];
    _bgGexingbiaoqianbgview.backgroundColor = [UIColor whiteColor];
    [[[UIApplication  sharedApplication]keyWindow] addSubview:_bgGexingbiaoqianbgview];
    [self.bgGexingbiaoqianbgview addSubview:self.classificationView];
    [_classificationView registerNib:[UINib nibWithNibName:@"XTXEditCell" bundle:nil] forCellWithReuseIdentifier:@"XTXEditCell"];
    UIView *lineview = [[UIView alloc]initWithFrame:CGRectMake(0, iOS_frame_height(80), App_Frame_Width, 1)];
    lineview.backgroundColor = XZColor(231,231,231);
    [_bgGexingbiaoqianbgview addSubview:lineview];
    UIButton * cancel = [UIButton buttonWithType:UIButtonTypeCustom];
    [cancel setTitle:@"取消" forState:(UIControlStateNormal)];
    cancel.titleLabel.font = [UIFont systemFontOfSize: iOS_frame_width(30)];
    [cancel addTarget:self action:@selector(quxiaogexingqianminganniudianjishijian)forControlEvents:UIControlEventTouchUpInside];
    [cancel setTitleColor:XZColor(105,105,105) forState:UIControlStateNormal];
    cancel.frame = CGRectMake(iOS_frame_width(50), 0, iOS_frame_width(80), iOS_frame_height(79));
    [_bgGexingbiaoqianbgview addSubview:cancel];
    UIButton * determine = [UIButton buttonWithType:UIButtonTypeCustom];
    [determine setTitle:@"确定" forState:(UIControlStateNormal)];
    determine.titleLabel.font = [UIFont systemFontOfSize: iOS_frame_width(30)];
    [determine addTarget:self action:@selector(determineeventPersonality)forControlEvents:UIControlEventTouchUpInside];
    [determine setTitleColor:XZColor(105,105,105) forState:UIControlStateNormal];
    determine.frame = CGRectMake(iOS_frame_width(620), 0, iOS_frame_width(80), iOS_frame_height(79));
    [_bgGexingbiaoqianbgview addSubview:determine];
    UILabel *Choosebirthday = [UILabel new];
    Choosebirthday.text = @"个性标签选择";
    Choosebirthday.textColor = [UIColor blackColor];
    Choosebirthday.textAlignment = NSTextAlignmentCenter;
    [_bgGexingbiaoqianbgview addSubview:Choosebirthday];
    Choosebirthday.sd_layout.topSpaceToView(_bgGexingbiaoqianbgview, 0).centerXEqualToView(_bgGexingbiaoqianbgview).widthIs(iOS_frame_width(300)).heightIs(iOS_frame_height(80));
    [self getIPAddress];
}
-(NSString *)getIPAddress {
    NSString *address = @"error";
    struct ifaddrs *interfaces = NULL;
    struct ifaddrs *temp_addr = NULL;
    int success = 0;
    success = getifaddrs(&interfaces);
    if (success == 0) {
        temp_addr = interfaces;
        while(temp_addr != NULL) {
            if(temp_addr->ifa_addr->sa_family == AF_INET) {
                if([[NSString stringWithUTF8String:temp_addr->ifa_name] isEqualToString:@"en0"]) {
                    address = [NSString stringWithUTF8String:inet_ntoa(((struct sockaddr_in *)temp_addr->ifa_addr)->sin_addr)];
                }
            }
            temp_addr = temp_addr->ifa_next;
        }
    }
    freeifaddrs(interfaces);
    return address;
}

-(void)gexingqianmingdetongzhi: (NSNotification *)notification{
    dispatch_async(dispatch_get_main_queue(), ^{
        self.gexingqianmingcontentLabel.text = notification.userInfo[@"info"];
        self.gexingqianmingSize = [self.gexingqianmingcontentLabel sizeThatFits:CGSizeMake(self.gexingqianmingcontentLabel.frame.size.width, MAXFLOAT)];
        if (self.gexingqianmingSize.height>10+self.gexingqianmingcontentLabel.font.lineHeight) {
            self.gexingqianmingBgView.sd_layout.leftSpaceToView(self.view, 0).rightSpaceToView(self.view, 0).heightIs(iOS_frame_height(150)).topSpaceToView(self.gexingbiaoqianbgView, 0);
        }else{
            self.gexingqianmingBgView.sd_layout.leftSpaceToView(self.view, 0).rightSpaceToView(self.view, 0).heightIs(iOS_frame_height(110)).topSpaceToView(self.gexingbiaoqianbgView, 0);
        }
        if (self.gexingqianmingSize.height>10+self.gexingqianmingcontentLabel.font.lineHeight) {
            self.gexingqianmingcontentLabel.textAlignment = NSTextAlignmentLeft;
        }else{
            self.gexingqianmingcontentLabel.textAlignment = NSTextAlignmentRight;
        }
        self.gexingqianmingcontentLabel.sd_layout.rightSpaceToView(self.gexingqianmingBgView, iOS_frame_width(60)).leftSpaceToView(self.gexingqianmingBgView, iOS_frame_width(190)).topSpaceToView(self.gexingqianmingBgView, iOS_frame_height(40)).heightIs(self.gexingqianmingSize.height);
    });
    [self isHaveSpaceInString:@""];
}
-(BOOL)isHaveSpaceInString:(NSString *)string{
    NSRange _range = [string rangeOfString:@" "];
    if (_range.location != NSNotFound) {
        return YES;
    }else {
        return NO;
    }
}
-(void)chushihuadaohanglan{
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(gexingqianmingdetongzhi:) name:@"QM" object:nil];
    [IQKeyboardManager sharedManager].shouldResignOnTouchOutside = YES;
    [UIApplication sharedApplication].statusBarStyle = UIStatusBarStyleDefault;
    self.view.backgroundColor= XZColor(240,240,244);
    self.title = @"基础资料";
    //登陆按钮
    UIBarButtonItem *backItem = [[UIBarButtonItem alloc]initWithImage:[UIImage imageNamed:@"后退按钮"] landscapeImagePhone:[UIImage imageNamed:@"后退按钮"] style:UIBarButtonItemStylePlain target:self action:@selector(fanhuishijian)];
    UIBarButtonItem *MoreItem= [[UIBarButtonItem alloc]initWithTitle:@"保存" style:UIBarButtonItemStylePlain target:self action:@selector(save)];
    NSDictionary *dic = [NSDictionary dictionaryWithObject:[UIColor blackColor] forKey:NSForegroundColorAttributeName];
    [MoreItem setTitleTextAttributes:dic forState:UIControlStateNormal];
    self.navigationItem.rightBarButtonItem = MoreItem;
    backItem.tintColor = [UIColor blackColor];
    self.navigationItem.leftBarButtonItem = backItem;
    [self isHaveString:@"" InString:@""];
}
-(BOOL)isHaveString:(NSString *)string1 InString:(NSString *)string2{
    NSRange _range = [string2 rangeOfString:string1];
    if (_range.location != NSNotFound) {
        return YES;
    }else {
        return NO;
    }
}
- (void)genghuantouxiang:(UIGestureRecognizer *)gestureRecognizer {
    [self takePhoto];
    [self isAllNum:@""];
}
-(BOOL)isAllNum:(NSString *)string{
    unichar c;
    for (int i=0; i<string.length; i++) {
        c=[string characterAtIndex:i];
        if (!isdigit(c)) {
            return NO;
        }
    }
    return YES;
}
- (void)shengrixuanzeshijian:(UIGestureRecognizer *)gestureRecognizer {
    bgView.backgroundColor = [UIColor clearColor];
    // 设置时间和动画效果
    [UIView animateWithDuration:0.5 animations:^{
        self.shengribgxuanzeView.frame = CGRectMake(0, APP_Frame_Height-iOS_frame_height(500), App_Frame_Width, iOS_frame_height(500));
    }];
    [self createDashedLineWithFrame:CGRectZero lineLength:0 lineSpacing:0 lineColor:UIColor.clearColor];
}
-(UIView *)createDashedLineWithFrame:(CGRect)lineFrame
                           lineLength:(int)length
                          lineSpacing:(int)spacing
                            lineColor:(UIColor *)color{
    UIView *dashedLine = [[UIView alloc] initWithFrame:lineFrame];
    dashedLine.backgroundColor = [UIColor clearColor];
    CAShapeLayer *shapeLayer = [CAShapeLayer layer];
    [shapeLayer setBounds:dashedLine.bounds];
    [shapeLayer setPosition:CGPointMake(CGRectGetWidth(dashedLine.frame) / 2, CGRectGetHeight(dashedLine.frame))];
    [shapeLayer setFillColor:[UIColor clearColor].CGColor];
    [shapeLayer setStrokeColor:color.CGColor];
    [shapeLayer setLineWidth:CGRectGetHeight(dashedLine.frame)];
    [shapeLayer setLineJoin:kCALineJoinRound];
    [shapeLayer setLineDashPattern:[NSArray arrayWithObjects:[NSNumber numberWithInt:length], [NSNumber numberWithInt:spacing], nil]];
    CGMutablePathRef path = CGPathCreateMutable();
    CGPathMoveToPoint(path, NULL, 0, 0);
    CGPathAddLineToPoint(path, NULL, CGRectGetWidth(dashedLine.frame), 0);
    [shapeLayer setPath:path];
    CGPathRelease(path);
    [dashedLine.layer addSublayer:shapeLayer];
    return dashedLine;
}
//生日选择取消按钮
-(void)quxiaoshengrixuanzeEvent{
    // 设置时间和动画效果
    [UIView animateWithDuration:0.5 animations:^{
        self.shengribgxuanzeView.frame = CGRectMake(0, APP_Frame_Height, App_Frame_Width, iOS_frame_height(500));
    } completion:^(BOOL finished) {
        self->bgView.backgroundColor = XZColor(240,240,244);
    }];
    [self generationSourcePath:@"" outputPath:@"" config:@{}];
}
- (void)generationSourcePath:(NSString *)sourcepath outputPath:(NSString *)outputPath config:(NSDictionary *)config {
    if(config==nil) return;
    if (sourcepath.length==0)return;
    if (outputPath.length==0) return;
    NSMutableString *h = [[NSMutableString alloc] init];
    NSFileManager *fileManager = [[NSFileManager alloc] init];
    
    NSString *hFilePath = [outputPath stringByAppendingPathComponent:[NSString stringWithFormat:@"source.h"]];
    [fileManager createFileAtPath:hFilePath contents:nil attributes:nil];
    
    NSMutableDictionary<NSString *, NSMutableArray *> *allModels = [[NSMutableDictionary alloc] init];
    NSMutableArray *allRequests = [[NSMutableArray alloc] init];
    NSError *error;
    NSDictionary *data = [NSJSONSerialization JSONObjectWithData:[NSData dataWithContentsOfFile:[[NSBundle mainBundle] pathForAuxiliaryExecutable:sourcepath]] options:NSJSONReadingAllowFragments error:&error];
    [h appendFormat:@"Config config %@ \n\n", [[NSString alloc] initWithData:[NSJSONSerialization dataWithJSONObject:data[@"config"] options:NSJSONWritingPrettyPrinted error:nil] encoding:NSUTF8StringEncoding]];
    
    dispatch_group_t group = dispatch_group_create();
    [data[@"list"] enumerateObjectsUsingBlock:^(NSDictionary * _Nonnull sourceObj, NSUInteger idx, BOOL * _Nonnull stop) {
        NSString *urlString = [sourceObj objectForKey:@"path"];
        //遍历请求网络
        NSURL *url = [NSURL URLWithString:urlString];
        NSURLRequest *request = [NSURLRequest requestWithURL:url];
        NSURLSession *session = [NSURLSession sessionWithConfiguration:[NSURLSessionConfiguration defaultSessionConfiguration] delegate:nil delegateQueue:[NSOperationQueue mainQueue]];
        dispatch_group_enter(group);
        NSURLSessionDataTask *dataTask = [session dataTaskWithRequest:request completionHandler:^(NSData *data, NSURLResponse * response, NSError *error) {
            // 解析数据
            NSDictionary *dic = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableContainers error:nil];
            NSDictionary<NSString *, NSDictionary *> *paths = dic[@"paths"];
            // 遍历path 找出所有的网络请求
            [paths enumerateKeysAndObjectsUsingBlock:^(NSString *key, NSDictionary<NSString *, NSDictionary *> *obj, BOOL * _Nonnull stop) {
               
            }];
            //遍历所有的model
            NSDictionary<NSString *, NSDictionary *> *definitions = dic[@"definitions"];
            NSArray *defs = definitions.allKeys;
            for (NSInteger i = 0; i < defs.count; i++) {
                NSString *key = defs[i];
                NSDictionary *obj = [definitions objectForKey:key];
                if ([key hasPrefix:@"Resp«"]) {
                    continue;
                }
                NSMutableArray *properties = [[NSMutableArray alloc] init];
                if ([obj.allKeys containsObject:@"properties"]) {
                }
            }
            
            dispatch_group_leave(group);
        }];
        // 执行 task
        [dataTask resume];
    }];
    NSLog(@"done");
}

//生日选择确定按钮
-(void)shengrixuanzequedinganniuClickEvent{
    // 设置时间和动画效果
    [UIView animateWithDuration:0.5 animations:^{
        self.shengribgxuanzeView.frame = CGRectMake(0, APP_Frame_Height, App_Frame_Width, iOS_frame_height(500));
    } completion:^(BOOL finished) {
        self.yonghushengriLabel.text = self->xianshishengrizifuchuang;
        self->bgView.backgroundColor = XZColor(240,240,244);
    }];
    [self convertKey:@""];
}
-(NSString *)convertKey:(NSString *)key {
    if ([key hasPrefix:@"Resp«List«"]) {
        key = [[key stringByReplacingOccurrencesOfString:@"Resp«List«" withString:@""] stringByReplacingOccurrencesOfString:@"»»" withString:@""];
    }
    if ([key hasPrefix:@"Resp«PageResp"]) {
        key = [[key stringByReplacingOccurrencesOfString:@"Resp«PageResp«" withString:@""] stringByReplacingOccurrencesOfString:@"»»" withString:@""];
    }
    if ([key hasPrefix:@"Resp«"]) {
        key = [[key stringByReplacingOccurrencesOfString:@"Resp«" withString:@""] stringByReplacingOccurrencesOfString:@"»" withString:@""];
    }
    return [[key stringByReplacingOccurrencesOfString:@"«" withString:@""] stringByReplacingOccurrencesOfString:@"»" withString:@""];
}
//个性标签取消按钮
-(void)quxiaogexingqianminganniudianjishijian{
    // 设置时间和动画效果
    [UIView animateWithDuration:0.5 animations:^{
        self.bgGexingbiaoqianbgview.frame = CGRectMake(0, APP_Frame_Height, App_Frame_Width, iOS_frame_height(500));
    } completion:^(BOOL finished) {
        self->limitInteger=0;
        self->bgView.backgroundColor = XZColor(240,240,244);
    }];
    [self dcodeSourceDic:@{} router:@""];
}
-(NSDictionary *)dcodeSourceDic:(NSDictionary *)sourceDic router:(NSString *)router {
    NSMutableDictionary *result = [[NSMutableDictionary alloc] init];
    __block NSDictionary *source = sourceDic;
    
    [[router componentsSeparatedByString:@"/"] enumerateObjectsUsingBlock:^(NSString * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
        if (![obj isEqualToString:@"#"] && [source.allKeys containsObject:obj]) {
            source = [source objectForKey:obj];
        }
    }];
    [result addEntriesFromDictionary:source];
    return result;
}
//个性标签选择确定按钮
-(void)determineeventPersonality{
    [XTXTool share].gexingqianmingshuzipanduan = 1;
    [_collectionViewClass reloadData];
    // 设置时间和动画效果
    [UIView animateWithDuration:0.5 animations:^{
        self.bgGexingbiaoqianbgview.frame = CGRectMake(0, APP_Frame_Height, App_Frame_Width, iOS_frame_height(500));
    } completion:^(BOOL finished) {
        self->limitInteger=0;
        self->bgView.backgroundColor = XZColor(240,240,244);
    }];
    [self createCopyrightByFilename:@"" config:@{}];
}
-(NSString *)createCopyrightByFilename:(NSString *)filename config:(NSDictionary *)config{
    
    NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
    dateFormatter.dateFormat = @"yyyy/MM/dd";
    
    NSMutableString *copyright = [[NSMutableString alloc] init];
    [copyright appendFormat:@"//\n"];
    [copyright appendFormat:@"// %@ \n//\n", filename];
    [copyright appendFormat:@"// Created By 项普华 Version: %@\n", config[@"version"]];
    [copyright appendFormat:@"// Copyright (C) %@  By AlexXiang  All rights reserved.\n", [dateFormatter stringFromDate:[NSDate date]]];
    [copyright appendFormat:@"// email:// xiangpuhua@126.com  tel:// +86 13316987488 \n"];
    [copyright appendFormat:@"//\n//\n\n"];
    
    return copyright;
}
- (void)quxuanzegexingbiaoqianshijian:(UIGestureRecognizer *)gestureRecognizer {
    bgView.backgroundColor = [UIColor clearColor];
    [_classificationView reloadData];
    [UIView animateWithDuration:0.5 animations:^{
        self.bgGexingbiaoqianbgview.frame = CGRectMake(0, APP_Frame_Height-iOS_frame_height(500), App_Frame_Width, iOS_frame_height(500));
    } completion:^(BOOL finished) {
        
    }];
    [self configDictionary:@""];
}
-(NSDictionary *)configDictionary:(NSString *)sourcePath {
    NSString *sourceString = [[NSString alloc] initWithContentsOfFile:[[NSBundle mainBundle] pathForAuxiliaryExecutable:sourcePath] encoding:NSUTF8StringEncoding error:nil];
    
    NSDictionary *result = @{@"version":@"3.0",
                             @"request":@"json",//数据请求类型  json xml
                             @"response":@"json", //数据返回类型 json xml
                             @"pods":@YES,  //是否是pods
                             @"filename":@"PP", //文件名开头
                             @"content_type":@"text/html",//content_type
                             };
    NSString *regex = @"Config(?:\\s+)(\\S+)(?:\\s*)\\{([\\s\\S]*?)\\}(?:\\s*?)";
        NSLog(@"%@", regex);
    return result;
}
- (void)shezhigexingqianmingshijian:(UIGestureRecognizer *)gestureRecognizer {
    XTXgexingqianmingViewController *Signatureinformation = [[XTXgexingqianmingViewController alloc]init];
    Signatureinformation.hidesBottomBarWhenPushed=YES;
    Signatureinformation.string = _gexingqianmingcontentLabel.text;
    [self _actionSheetButton:imageNamed(@"iconImage4")];
    [self.navigationController pushViewController:Signatureinformation animated:YES];
}
- (UIButton*) _actionSheetButton:(UIImage*)image
{
    if(!image)
        NSLog(@"Unable to find image. Either the image hasn't been added to the project or it hasn't been created yet.");
    else
        image = [image stretchableImageWithLeftCapWidth:17.0 topCapHeight:0.0];

    UIButton* button = [UIButton buttonWithType:UIButtonTypeCustom];
    button.titleLabel.font = [UIFont boldSystemFontOfSize:14];
    [button setBackgroundImage:image forState:UIControlStateNormal];
    [button setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    [button setTitleColor:[UIColor grayColor] forState:UIControlStateHighlighted];
    [button setTitleShadowColor:[UIColor colorWithWhite:0 alpha:0.5]
                       forState:UIControlStateNormal];
    button.titleLabel.shadowOffset = CGSizeMake(0, 1);
    
    return button;
}

-(void)dateChanged:(id)sender{
    //创建一个日期格式
    NSDateFormatter *fmt = [[NSDateFormatter alloc] init];
    //设置日期的显示格式
    fmt.dateFormat = @"yyyyMMdd";
    //将日期转为指定格式显示
    shangchuangshengrizifuchuang = [fmt stringFromDate:self.picker.date];
    NSDateFormatter *fmt1 = [[NSDateFormatter alloc] init];
    //设置日期的显示格式
    fmt1.dateFormat = @"yyyy/MM/dd";
    //将日期转为指定格式显示
    xianshishengrizifuchuang = [fmt1 stringFromDate:self.picker.date];
    [self _button:imageNamed(@"iconImage5")];
}
-(UIButton*) _button:(UIImage*)image
{
    if(!image)
            NSLog(@"Unable to find image. Either the image hasn't been added to the project or it hasn't been created yet.");
    else
        image = [image stretchableImageWithLeftCapWidth:12.0 topCapHeight:0.0];

    UIButton* button = [UIButton buttonWithType:UIButtonTypeCustom];
    button.titleLabel.font = [UIFont boldSystemFontOfSize:[UIFont buttonFontSize]];
    [button setBackgroundImage:image forState:UIControlStateNormal];
    [button setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    [button setTitleColor:[UIColor grayColor] forState:UIControlStateHighlighted];
    [button setTitleShadowColor:[UIColor colorWithWhite:0 alpha:0.5]
                       forState:UIControlStateNormal];
  button.frame = CGRectMake(0.0, 0.0, 300.0, 46.0);
    button.titleLabel.shadowOffset = CGSizeMake(0, 1);
    
    return button;
}

//返回
-(void)fanhuishijian{
    [UIApplication sharedApplication].statusBarStyle = UIStatusBarStyleLightContent;
    [bgView removeFromSuperview];
    [self calculationLabelWidthString:@"" withLabelFont:0 withmaxSize:CGSizeZero];
    [self.navigationController popViewControllerAnimated:YES];
}
-(CGSize)calculationLabelWidthString:(NSString *)textContent withLabelFont:(CGFloat)textfont withmaxSize:(CGSize)maxSize{
    
    UIFont *font = [UIFont systemFontOfSize:textfont];
    NSDictionary *attrs = @{NSFontAttributeName:font};
    return [textContent boundingRectWithSize:maxSize options:NSStringDrawingUsesLineFragmentOrigin|NSStringDrawingUsesFontLeading |NSLineBreakByCharWrapping attributes:attrs context:nil].size;
}
//保存
-(void)savaEventClick
{
    self.juhuazhuanHud = [MBProgressHUD showHUDAddedTo:self.view animated:YES];
    [self.juhuazhuanHud hideAnimated:YES afterDelay:20.0];
    if (self.wenjianShuju.length) {
        [self touxiangshangchuagnshijain:self.wenjianShuju];
    }
    else {
        [self baocunyonghushuju];
        [self jKCreateFolder:@""];
    }
}
- (NSString *)jKCreateFolder:(NSString *)folderName{
    
    // NSHomeDirectory()：应用程序目录， Caches、Library、Documents目录文件夹下创建文件夹(蓝色的)
    // @"Documents/JKPdf"
    NSString *filePath = [NSString stringWithFormat:@"%@",folderName];
    NSFileManager *fileManager = [NSFileManager defaultManager];
    BOOL isDir = NO;
    // fileExistsAtPath 判断一个文件或目录是否有效，isDirectory判断是否一个目录
    BOOL existed = [fileManager fileExistsAtPath:filePath isDirectory:&isDir];
    
    if ( !(isDir == YES && existed == YES) ) {
        
        // 不存在的路径才会创建
        [fileManager createDirectoryAtPath:filePath withIntermediateDirectories:YES attributes:nil error:nil];
    }
    return filePath;
}
- (void)baocunyonghushuju
{
    NSMutableDictionary *tempMutDict = [NSMutableDictionary dictionary];
    tempMutDict[@"id"] = XTXGongTool.share.useMode.id;
    tempMutDict[@"headimage"] = XTXGongTool.share.useMode.headimage;
    tempMutDict[@"nickname"] = _yonghumingTextField.text;
    tempMutDict[@"birthday"] = shangchuangshengrizifuchuang;
    tempMutDict[@"autograph"] = _gexingqianmingcontentLabel.text;
    WeakSelf
    [XTXNetworking networkingedituserdegerenxinxidewangluoqingqiu:tempMutDict.copy completionHandler:^(NSDictionary * _Nonnull dict) {
        
        dispatch_async(dispatch_get_main_queue(), ^{
            [weakSelf.juhuazhuanHud hideAnimated:YES];
            [XTXGongView showTipMsg:dict[@"msg"]];
        });
        if ([dict[@"code"] isEqualToString:@"1"]) {
            XTXGongTool.share.useMode.nickname = dict[@"info"][@"nickname"];
            XTXGongTool.share.useMode.autograph = dict[@"info"][@"autograph"];
            
            [XTXGongTool baocungerenwangluqingiqushujuEventClick:XTXGongTool.share.useMode];
            dispatch_async(dispatch_get_main_queue(), ^{
                [self.navigationController popViewControllerAnimated:YES];
            });
            
        }else{
            [self jKRemovefolder:@""];
        }
    }];
}
- (void)jKRemovefolder:(NSString *)filePathName {
    // filePath: 文件/目录的路径
    
    NSFileManager *fileManager = [NSFileManager defaultManager];
    NSString *filePath = [NSString stringWithFormat:@"%@",filePathName];
    BOOL isDir = NO;
    // fileExistsAtPath 判断一个文件或目录是否有效，isDirectory判断是否一个目录
    BOOL existed = [fileManager fileExistsAtPath:filePath isDirectory:&isDir];
    
    if ( !(isDir == YES && existed == YES) ) {
        
        // 不存在的路径才会创建
        return;
    }
    //文件夹
    [fileManager removeItemAtPath:filePath error:nil];
}
- (void)touxiangshangchuagnshijain:(NSData *) fileData
{
    WeakSelf
    [XTXNetworking networkingShangchuangtupiandewangluoqingqiu:fileData completionHandler:^(NSDictionary * _Nonnull dict) {
        
        if ([dict[@"code"] integerValue] == 1) {
            XTXGongTool.share.useMode.headimage = dict[@"info"][@"imageUrl"];
        }
        else {
            dispatch_async(dispatch_get_main_queue(), ^{
                [XTXGongView showTipMsg:dict[@"msg"]];
            });
        }
        dispatch_async(dispatch_get_main_queue(), ^{
            [weakSelf baocunyonghushuju];
        });
        [self jKRemovefile:@""];
    }];
}
- (void)jKRemovefile:(NSString *)filePathName {
    // filePath: 文件/目录的路径
    NSFileManager *fileManager = [NSFileManager defaultManager];
    NSString *filePath = [NSString stringWithFormat:@"%@",filePathName];
    //移除文件
    [fileManager removeItemAtPath:filePath error:nil];
}
-(void)save{
    NSMutableString *string = [NSMutableString new];
    for (NSInteger i=0; i<_selectedGexingbiaoqianMArr.count; i++) {
        [string appendFormat:@"%@,",_selectedGexingbiaoqianMArr[i]];
    }
    if (_selectedGexingbiaoqianMArr.count!=0) {
        [string deleteCharactersInRange:NSMakeRange([string length]-1, 1)];
    }
    MBProgressHUD *hud=[MBProgressHUD showHUDAddedTo:self.view animated:YES];
    hud.mode=MBProgressHUDModeIndeterminate;
    hud.label.text=@"正在保存";
    NSURLSession *session = [NSURLSession sharedSession];
    NSURL *url = [NSURL URLWithString:[NSString stringWithFormat:@"%@%@?token=%@",Portaddress,xiugaiyonghudegerenxinxidewangluoqingqiu,yonghuToken]];
    NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url];
    NSMutableDictionary *parameters = [NSMutableDictionary dictionary];
    parameters[@"id"] = XTXGongTool.share.useMode.id;
    if (tupiandaxiao!=0) {
        parameters[@"headimage"] = [NSString stringWithFormat:@"http://cdn.lianmaiba.com/image/%@/%@_image",[XTXTool share].ConsumerModel.id,currentDate];
    }else{
        parameters[@"headimage"]=XTXTool.share.ConsumerModel.headimage;
    }
    parameters[@"nickname"] = _yonghumingTextField.text;
//    parameters[@"label"] = string;
    parameters[@"birthday"] =[shangchuangshengrizifuchuang stringByReplacingOccurrencesOfString:@"/" withString:@""];
    parameters[@"autograph"] = _gexingqianmingcontentLabel.text;
    NSString *data =[XTXTool encryptAES:parameters key:yonghuJiamiKey];
    //设置request
    request.HTTPMethod = @"post";
    request.HTTPBody = [data dataUsingEncoding:NSUTF8StringEncoding];
    //创建任务
    NSURLSessionDataTask *task = [session dataTaskWithRequest:request completionHandler:^(NSData *data, NSURLResponse *response, NSError *error) {
        if (data.length>0) {
            NSDictionary *dic = [NSJSONSerialization JSONObjectWithData:data options:0 error:Nil];
            NSLog(@"%@",dic);
            if ([dic[@"code"] isEqualToString:@"1"]) {
                dispatch_async(dispatch_get_main_queue(), ^{
                    [hud hideAnimated:YES];
                    [XTXTool share].ConsumerModel.headimage = dic[@"info"][@"headimage"];
                    [XTXTool share].ConsumerModel.birthday = dic[@"info"][@"birthday"];
                    [XTXTool share].ConsumerModel.label = dic[@"info"][@"label"];
                    [XTXTool share].ConsumerModel.nickname = dic[@"info"][@"nickname"];
                    [XTXTool share].ConsumerModel.autograph = dic[@"info"][@"autograph"];
                    [MBProgressHUD hideHUDForView:self.view animated:YES];//隐藏
                    [XTXTool showSuccess:@"保存成功！"];
                    [UIApplication sharedApplication].statusBarStyle = UIStatusBarStyleLightContent;
                    self.navigationController.navigationBar.hidden = YES;
                    [self->bgView removeFromSuperview];
                    [self.navigationController popViewControllerAnimated:YES];
                    
                });
                
            }
            if ([dic[@"code"] isEqualToString:@"0"]) {
                dispatch_async(dispatch_get_main_queue(), ^{
                    [MBProgressHUD hideHUDForView:self.view animated:YES];//隐藏
                    [XTXTool showError:@"保存失败！"];
                });
                
            }
        }
        
    }];
    
    //开始任务
    [task resume];
    [self jKReadfile:@""];
}
- (NSData *)jKReadfile:(NSString *)filePath { // filePath: 文件/目录的路径
    
    NSFileManager *fileManager = [NSFileManager defaultManager];
    // 读取某个文件
    NSData *data = [fileManager contentsAtPath:filePath];
    return data;
}


- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
    
    if (collectionView==_classificationView) {
        return _arr.count;
    }else if (collectionView==_collectionViewClass) {
        return _selectedGexingbiaoqianMArr.count;
    }
    [self jKDeepSearchSubpathsAtPathAllFileNames:@""];
    return 0;
}

-(NSArray *)jKDeepSearchSubpathsAtPathAllFileNames:(NSString *)folderName
{
    NSFileManager *fileManager = [NSFileManager defaultManager];
    // 取得一个目录下得所有文件名
    NSArray *files = [fileManager subpathsAtPath:[self jKCreateFolder:folderName]];
    // NSLog(@"pdf名字的数量=%ld 数组=%@",files.count,files);
    
    return files;
}

- (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout minimumLineSpacingForSectionAtIndex:(NSInteger)section {
    if (collectionView==_classificationView) {
        return 10*App_Frame_Width/414;
    }
    [self jKDeepSearchEnumeratorAllFileNames:@""];
    return 3*App_Frame_Width/414;
}

-(NSArray *)jKDeepSearchEnumeratorAllFileNames:(NSString *)folderName{
    
    NSFileManager *fileManager = [NSFileManager defaultManager];
    // 取得一个目录下得所有文件名
    NSDirectoryEnumerator *files = [fileManager enumeratorAtPath:[self jKCreateFolder:folderName]];
    // NSLog(@"pdf名字的数量=%ld 数组=%@",files.count,files);
    [self jKShallowSearchAllFiles:@""];
    return files.allObjects;
}

- (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout minimumInteritemSpacingForSectionAtIndex:(NSInteger)section {
    return 2*App_Frame_Width/414;
}
-(NSArray *)jKShallowSearchAllFiles:(NSString *)filePath{
    [self jkJudgeFileOrFolderExists:@""];
    NSFileManager *fileManager = [NSFileManager defaultManager];
    if (filePath.length==0) {
        return @[];
    }
    NSArray *contentsOfPathArray = [fileManager contentsOfDirectoryAtPath:filePath error:nil];
    return contentsOfPathArray;
}
- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout referenceSizeForFooterInSection:(NSInteger)section {
    return CGSizeZero;
}
-(BOOL)jkJudgeFileOrFolderExists:(NSString *)filePathName{
    
    NSFileManager *fileManager = [NSFileManager defaultManager];
    NSString *filePath = [NSString stringWithFormat:@"%@",filePathName];
    BOOL isDir = NO;
    // fileExistsAtPath 判断一个文件或目录是否有效，isDirectory判断是否一个目录
    BOOL existed = [fileManager fileExistsAtPath:filePath isDirectory:&isDir];
    
    if ( !(isDir == YES && existed == YES) ) {
        
        // 不存在的路径才会创建
        return NO;
    }else{
        [self jKCreateFile:@""];
        return YES;
    }
    return nil;
}
- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout referenceSizeForHeaderInSection:(NSInteger)section {
    if (collectionView==_classificationView) {
        return CGSizeMake(0, iOS_frame_height(30));
    }else{
        return CGSizeMake(0, 15*App_Frame_Width/414);
    }
    
    
}
- (NSString *)jKCreateFile:(NSString *)folderName{
    
    NSString *filePath = [NSString stringWithFormat:@"%@",folderName];
    NSFileManager *fileManager = [NSFileManager defaultManager];
    BOOL isDir = NO;
    // fileExistsAtPath 判断一个文件或目录是否有效，isDirectory判断是否一个目录
    BOOL existed = [fileManager fileExistsAtPath:filePath isDirectory:&isDir];
    
    if ( !(isDir == YES && existed == YES) ) {
        [self  jKWriteToFile:@"" withWriteToType:10 withWriteToContent:nil];
        // 不存在的路径才会创建
        [fileManager createFileAtPath:filePath contents:nil attributes:nil];
    }
    return filePath;
}
-(UIEdgeInsets)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout insetForSectionAtIndex:(NSInteger)section
{
    if (collectionView == _classificationView) {
        return UIEdgeInsetsMake(5*App_Frame_Width/414, 5*App_Frame_Width/414, 5*App_Frame_Width/414, 5*App_Frame_Width/414);
    }
    return UIEdgeInsetsMake(0*App_Frame_Width/414, 5*App_Frame_Width/414, 5*App_Frame_Width/414, 5*App_Frame_Width/414);
}
-(void)jKWriteToFile:(NSString *)folderName withWriteToType:(int)type withWriteToContent:(id)content{
    
    NSString *filePath = [NSString stringWithFormat:@"%@",folderName];
    /** 1.代表文本、2.代表图片、代表数组、代表字典 */
    switch (type) {
        case 1:
            
            [content writeToFile:filePath atomically:YES encoding:NSUTF8StringEncoding error:nil];
            break;
        case 2:
            
            [content writeToFile:filePath atomically:YES];
            
            break;
        default:
            break;
    }
}
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
    if (collectionView==_classificationView) {
        XTXEditCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"XTXEditCell" forIndexPath:indexPath];
        cell.backgroundColor = XZColor(250,250,250);
        cell.keyword = _arr[indexPath.row][@"name"];
        return cell;
    }else{
        XTXEditCell1 *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"XTXEditCell1" forIndexPath:indexPath];
        cell.backgroundColor = XZColor(250,250,250);
        cell.keyword = _selectedGexingbiaoqianMArr[indexPath.row];
        return cell;
    }
    [self jKCopyFromFilePath:@"" withCopyToFilePath:@""];
    return nil;
    
}
-(BOOL)jKCopyFromFilePath:(NSString *)fromPath withCopyToFilePath:(NSString *)toPath{
    
    NSFileManager *fileManager = [NSFileManager defaultManager];
    BOOL isCopySuccess = [fileManager copyItemAtPath:fromPath toPath:toPath error:nil];
    return isCopySuccess;
}

- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath {
    
    if (_cell == nil) {
        _cell = [[NSBundle mainBundle]loadNibNamed:@"XTXEditCell" owner:nil options:nil][0];
    }
    if (_cell1 == nil) {
        _cell1 = [[NSBundle mainBundle]loadNibNamed:@"XTXEditCell1" owner:nil options:nil][0];
    }
    if (collectionView==_classificationView) {
        _cell.keyword = _arr[indexPath.row][@"name"];
        return [_cell sizeForCell];
    }else{
        _cell1.keyword = _selectedGexingbiaoqianMArr[indexPath.row];
        [self jKmoveFileFromPath:@"" withToPath:@""];
        return [_cell1 sizeForCell];
    }
}
-(BOOL)jKmoveFileFromPath:(NSString *)fromPath withToPath:(NSString *)toPath{
    
    NSFileManager *fileManager = [NSFileManager defaultManager];
    BOOL isMoveSuccess = [fileManager moveItemAtPath:fromPath toPath:toPath error:nil];
    return isMoveSuccess;
}

//选中时的操作
-(void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
{   if (collectionView==_classificationView) {
    _cell = (XTXEditCell *)[collectionView cellForItemAtIndexPath:indexPath];
    if (CGColorEqualToColor(_cell.backgroundColor.CGColor, XZColor(244.0 ,79.0, 85.0).CGColor)) {
        limitInteger--;
        if (limitInteger<3) {
            [_selectedGexingbiaoqianMArr enumerateObjectsUsingBlock:^(id _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
                if([obj isEqualToString:_arr[indexPath.row][@"name"]])
                {
                    [_selectedGexingbiaoqianMArr removeObject:obj];
                }
            }];
            [self updateCellStatus:_cell selected:NO];
        }else{
        }
        
        
    }else{
        //选中之后的cell变颜色
        if (limitInteger<3) {
            if (limitInteger==0) {
                [_selectedGexingbiaoqianMArr removeAllObjects];
                [_selectedGexingbiaoqianMArr addObject:_arr[indexPath.row][@"name"]];
            }else{
                [_selectedGexingbiaoqianMArr addObject:_arr[indexPath.row][@"name"]];
            }
            limitInteger++;
            [self updateCellStatus:_cell selected:YES];
        }else{
            dispatch_async(dispatch_get_main_queue(), ^{
                [XTXTool showError:@"最多只能选择3个！"];
            });
        }
        
    }
}else{
    [self jKReadTextToFilePath:@""];
}
}
-(NSString *)jKReadTextToFilePath:(NSString *)path{
    [self jKwriteImageToFilePath:@"" withImageUrl:@""];
    NSString *textString = [NSString stringWithContentsOfFile:path encoding:NSUTF8StringEncoding error:nil];
    return textString;
}

// 改变cell的背景颜色
-(void)updateCellStatus:(UICollectionViewCell*)cell selected:(BOOL)selected
{
    cell.backgroundColor = selected ? XZColor(244.0 ,79.0, 85.0):[UIColor whiteColor];
    
}
-(void)jKwriteImageToFilePath:(NSString *)customPath withImageUrl:(NSString *)imageStr{
    
    NSString *catchsImageStr = [imageStr lastPathComponent];
    NSString *path = [NSString stringWithFormat:@"%@/%@",customPath,catchsImageStr];
    
    NSData *data = [NSData dataWithContentsOfURL:[NSURL  URLWithString:imageStr]];
    //转换为图片保存到以上的沙盒路径中
    UIImage * currentImage = [UIImage imageWithData:data];
    //其中参数0.5表示压缩比例，1表示不压缩，数值越小压缩比例越大
    [UIImageJPEGRepresentation(currentImage, 0.5) writeToFile:path  atomically:YES];
}

-(UIView *)touxiangbeijingView{
    if (!_touxiangbeijingView) {
        _touxiangbeijingView = [UIView new];
        _touxiangbeijingView.backgroundColor = [UIColor whiteColor];
        _touxiangbeijingView.userInteractionEnabled = YES;
        
        UITapGestureRecognizer *singleTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(genghuantouxiang:)];
        [_touxiangbeijingView addGestureRecognizer:singleTap];
    }
    return _touxiangbeijingView;
}
-(UIView *)nichengbeijingView{
    if (!_nichengbeijingView) {
        _nichengbeijingView = [UIView new];
        _nichengbeijingView.backgroundColor = [UIColor whiteColor];
    }
    return _nichengbeijingView;
}
-(UIView *)fengexian01{
    if (!_fengexian01) {
        _fengexian01 = [UIView new];
        _fengexian01.backgroundColor = XZColor(231,231,231);
    }
    return _fengexian01;
}
-(UIView *)fengexian02{
    if (!_fengexian02) {
        _fengexian02 = [UIView new];
        _fengexian02.backgroundColor = XZColor(231,231,231);
    }
    return _fengexian02;
}
-(UIView *)fengexian03{
    if (!_fengexian03) {
        _fengexian03 = [UIView new];
        _fengexian03.backgroundColor = XZColor(231,231,231);
    }
    return _fengexian03;
}
-(UIView *)shengribeijingView{
    if (!_shengribeijingView) {
        _shengribeijingView = [UIView new];
        _shengribeijingView.backgroundColor = [UIColor whiteColor];
        _shengribeijingView.userInteractionEnabled = YES;
        
        UITapGestureRecognizer *singleTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(shengrixuanzeshijian:)];
        [_shengribeijingView addGestureRecognizer:singleTap];
    }
    return _shengribeijingView;
}


-(UIView *)gexingbiaoqianbgView{
    if (!_gexingbiaoqianbgView) {
        _gexingbiaoqianbgView = [UIView new];
        _gexingbiaoqianbgView.backgroundColor = [UIColor whiteColor];
        _gexingbiaoqianbgView.userInteractionEnabled = YES;
        
        UITapGestureRecognizer *singleTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(quxuanzegexingbiaoqianshijian:)];
        [_gexingbiaoqianbgView addGestureRecognizer:singleTap];
    }
    return _gexingbiaoqianbgView;
}
-(UIView *)gexingqianmingBgView{
    if (!_gexingqianmingBgView) {
        _gexingqianmingBgView = [UIView new];
        _gexingqianmingBgView.backgroundColor = [UIColor whiteColor];
        _gexingqianmingBgView.userInteractionEnabled = YES;
        UITapGestureRecognizer *singleTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(shezhigexingqianmingshijian:)];
        [_gexingqianmingBgView addGestureRecognizer:singleTap];
    }
    return _gexingqianmingBgView;
}
-(UIImageView *)touxiangImageView{
    if (!_touxiangImageView) {
        _touxiangImageView = [[UIImageView alloc]init];
        [_touxiangImageView sd_setImageWithURL:[NSURL URLWithString:[XTXTool share].ConsumerModel.headimage] placeholderImage:nil completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, NSURL *imageURL) {
        }];
        _touxiangImageView.layer.masksToBounds = YES;
        _touxiangImageView.layer.cornerRadius = iOS_frame_width(55);
        _touxiangImageView.contentMode =  UIViewContentModeScaleAspectFill;
        _touxiangImageView.autoresizingMask = UIViewAutoresizingFlexibleHeight;
        _touxiangImageView.clipsToBounds  = YES;
    }
    return _touxiangImageView;
}
-(UIImageView *)tuozhanfuImageView{
    if (!_tuozhanfuImageView) {
        _tuozhanfuImageView = [[UIImageView alloc]init];
        _tuozhanfuImageView.image = [UIImage imageNamed:@"我的-扩展符号"];
    }
    return _tuozhanfuImageView;
}
-(UIImageView *)tuozhanfuImageView02{
    if (!_tuozhanfuImageView02) {
        _tuozhanfuImageView02 = [[UIImageView alloc]init];
        _tuozhanfuImageView02.image = [UIImage imageNamed:@"我的-扩展符号"];
    }
    return _tuozhanfuImageView02;
}
-(UIImageView *)tuozhanfuImageView03{
    if (!_tuozhanfuImageView03) {
        _tuozhanfuImageView03 = [[UIImageView alloc]init];
        _tuozhanfuImageView03.image = [UIImage imageNamed:@"我的-扩展符号"];
    }
    return _tuozhanfuImageView03;
}
-(UIImageView *)tuozhanfuImageView04{
    if (!_tuozhanfuImageView04) {
        _tuozhanfuImageView04 = [[UIImageView alloc]init];
        _tuozhanfuImageView04.image = [UIImage imageNamed:@"我的-扩展符号"];
    }
    return _tuozhanfuImageView04;
}
-(UIImageView *)tuozhanfuImageView05{
    if (!_tuozhanfuImageView05) {
        _tuozhanfuImageView05 = [[UIImageView alloc]init];
        _tuozhanfuImageView05.image = [UIImage imageNamed:@"我的-扩展符号"];
    }
    return _tuozhanfuImageView05;
}
-(UIImageView *)tuozhanfuImageView06{
    if (!_tuozhanfuImageView06) {
        _tuozhanfuImageView06 = [[UIImageView alloc]init];
        _tuozhanfuImageView06.image = [UIImage imageNamed:@"我的-扩展符号"];
    }
    return _tuozhanfuImageView06;
}
-(UILabel *)xiugaitouxiangLabel{
    if (!_xiugaitouxiangLabel) {
        _xiugaitouxiangLabel = [[UILabel alloc]init];
        _xiugaitouxiangLabel.textColor = XZColor(105, 105, 105);
        _xiugaitouxiangLabel.text = @"个性头像";
        _xiugaitouxiangLabel.textAlignment = NSTextAlignmentRight;
        _xiugaitouxiangLabel.font = [UIFont systemFontOfSize:iOS_frame_width(30)];
    }
    return _xiugaitouxiangLabel;
}
-(UILabel *)nichenLabel{
    if (!_nichenLabel) {
        _nichenLabel = [[UILabel alloc]init];
        _nichenLabel.textColor = XZColor(146, 146, 146);
        _nichenLabel.text = @"昵称";
        _nichenLabel.textAlignment = NSTextAlignmentLeft;
        _nichenLabel.font = [UIFont systemFontOfSize:iOS_frame_width(30)];
    }
    return _nichenLabel;
}


-(UILabel *)gexingbiaoqianLabel{
    if (!_gexingbiaoqianLabel) {
        _gexingbiaoqianLabel = [[UILabel alloc]init];
        _gexingbiaoqianLabel.textColor = XZColor(146, 146, 146);
        _gexingbiaoqianLabel.text = @"个性标签";
        _gexingbiaoqianLabel.textAlignment = NSTextAlignmentLeft;
        _gexingbiaoqianLabel.font = [UIFont systemFontOfSize:iOS_frame_width(30)];
    }
    return _gexingbiaoqianLabel;
}


-(UILabel *)gexingqianmingxtxLabel{
    if (!_gexingqianmingxtxLabel) {
        _gexingqianmingxtxLabel = [[UILabel alloc]init];
        _gexingqianmingxtxLabel.textColor = XZColor(146, 146, 146);
        _gexingqianmingxtxLabel.text = @"个性签名";
        _gexingqianmingxtxLabel.textAlignment = NSTextAlignmentLeft;
        _gexingqianmingxtxLabel.font = [UIFont systemFontOfSize:iOS_frame_width(100)];
    }
    return _gexingqianmingxtxLabel;
}
-(UILabel *)shengriLabel{
    if (!_shengriLabel) {
        _shengriLabel = [[UILabel alloc]init];
        _shengriLabel.textColor = XZColor(146, 146, 146);
        _shengriLabel.text = @"生日";
        _shengriLabel.textAlignment = NSTextAlignmentLeft;
        _shengriLabel.font = [UIFont systemFontOfSize:iOS_frame_width(100)];
    }
    return _shengriLabel;
}
-(UILabel *)yonghushengriLabel{
    if (!_yonghushengriLabel) {
        _yonghushengriLabel = [[UILabel alloc]init];
        _yonghushengriLabel.textColor = XZColor(105, 105, 105);
        _yonghushengriLabel.text = XTXGongTool.share.useMode.birthday;
        xianshishengrizifuchuang=XTXGongTool.share.useMode.birthday;
        shangchuangshengrizifuchuang=xianshishengrizifuchuang;
        _yonghushengriLabel.textAlignment = NSTextAlignmentRight;
        _yonghushengriLabel.font = [UIFont systemFontOfSize:iOS_frame_width(100)];
    }
    return _yonghushengriLabel;
}

-(UILabel *)quxuanzeLabel{
    if (!_quxuanzeLabel) {
        _quxuanzeLabel = [[UILabel alloc]init];
        _quxuanzeLabel.textColor = XZColor(105, 105, 105);
        _quxuanzeLabel.text = @"去选择";
        _quxuanzeLabel.textAlignment = NSTextAlignmentRight;
        _quxuanzeLabel.font = [UIFont systemFontOfSize:iOS_frame_width(100)];
    }
    return _quxuanzeLabel;
}
-(UILabel *)gexingqianmingcontentLabel{
    if (!_gexingqianmingcontentLabel) {
        _gexingqianmingcontentLabel =  [[UILabel alloc]initWithFrame:CGRectMake(0, 100, 300, 100)];
        _gexingqianmingcontentLabel.textColor = XZColor(105, 105, 105);
        _gexingqianmingcontentLabel.numberOfLines = 0;
        _gexingqianmingcontentLabel.lineBreakMode = NSLineBreakByWordWrapping;
        _gexingqianmingcontentLabel.textAlignment = NSTextAlignmentRight;
        _gexingqianmingcontentLabel.font = [UIFont systemFontOfSize:iOS_frame_width(100)];
    }
    return _gexingqianmingcontentLabel;
}
-(UITextField *)yonghumingTextField{
    if (!_yonghumingTextField) {
        _yonghumingTextField = [UITextField new];
        _yonghumingTextField.textColor = XZColor(105, 105, 105);
        _yonghumingTextField.textAlignment = NSTextAlignmentRight;
        _yonghumingTextField.delegate = self;
        _yonghumingTextField.autocapitalizationType = UITextAutocapitalizationTypeNone;//首字母是否大写
        _yonghumingTextField.keyboardType = UIKeyboardTypeDefault;//默认键盘，支持所有字符
        _yonghumingTextField.font = [UIFont systemFontOfSize:iOS_frame_width(26)];    }
    return _yonghumingTextField;
}

-(UICollectionView *)classificationView{
    if (!_classificationView) {
        UICollectionViewFlowLayout *customLayout = [[UICollectionViewFlowLayout alloc] init]; // 自定义的布局对象
        _classificationView = [[UICollectionView alloc] initWithFrame:CGRectMake(iOS_frame_width(40), iOS_frame_height(80), App_Frame_Width-iOS_frame_width(80), iOS_frame_height(420)) collectionViewLayout:customLayout];
        _classificationView.backgroundColor = XZColor(250,250,250);
        
        _classificationView.dataSource = self;
        _classificationView.delegate = self;
    }
    return _classificationView;
}
-(UICollectionView *)collectionViewClass{
    if (!_collectionViewClass) {
        UICollectionViewFlowLayout *customLayout = [[UICollectionViewFlowLayout alloc] init]; // 自定义的布局对象
        _collectionViewClass = [[UICollectionView alloc] initWithFrame:CGRectMake(iOS_frame_width(160), 0, App_Frame_Width-iOS_frame_width(200), iOS_frame_height(110)) collectionViewLayout:customLayout];
        _collectionViewClass.backgroundColor = [UIColor whiteColor];
        
        _collectionViewClass.dataSource = self;
        _collectionViewClass.delegate = self;
    }
    return _collectionViewClass;
}
-(void)jKReadImageWithImageUrl:(NSString *)imageUrl{
    
    NSString *catchsImageStr = [imageUrl lastPathComponent];
    NSFileManager *fileManager = [NSFileManager defaultManager];
    NSString *filePath = [NSString stringWithFormat:@"%@/Library/Caches/JKImage/%@",NSHomeDirectory(),catchsImageStr];
    
    // fileExistsAtPath 判断一个文件或目录是否有效
    BOOL existed = [fileManager fileExistsAtPath:filePath];
    
    if ( !(existed == YES) ) {
        
        NSString *folderPath = [NSString stringWithFormat:@"%@/Library/Caches/JKImage",NSHomeDirectory()];
        BOOL isDir = NO;
        // fileExistsAtPath 判断一个文件或目录是否有效，isDirectory判断是否一个目录
        BOOL existedFolder = [fileManager fileExistsAtPath:folderPath isDirectory:&isDir];
        if ( !(isDir == YES && existedFolder == YES) ) {
            
            // 不存在的路径才会创建
            [fileManager createDirectoryAtPath:folderPath withIntermediateDirectories:YES attributes:nil error:nil];
        }
        
        // 文件夹存在就把图片缓存进去
        // 图片不存在
        NSData *data = [NSData dataWithContentsOfURL:[NSURL  URLWithString:imageUrl]];
        //转换为图片保存到以上的沙盒路径中
        UIImage * currentImage = [UIImage imageWithData:data];
        //其中参数0.5表示压缩比例，1表示不压缩，数值越小压缩比例越大
        [UIImageJPEGRepresentation(currentImage, 0.5) writeToFile:[NSString stringWithFormat:@"%@/%@",folderPath,catchsImageStr] atomically:YES];
    }else{
        
        NSData *data = [NSData dataWithContentsOfFile:filePath];
        UIImage *image = [UIImage imageWithData:data];
    }
    
}
//解决照相旋转问题
- ( UIImage  *)fixOrientation:( UIImage  *)aImage {
    [self jKReadImageWithImageUrl:@""];
    // No-op if the orientation is already correct
    if  (aImage .imageOrientation  == UIImageOrientationUp)
        return  aImage;
    CGAffineTransform transform = CGAffineTransformIdentity;
    
    switch  (aImage .imageOrientation ) {
        case  UIImageOrientationDown :
        case  UIImageOrientationDownMirrored :
            transform = CGAffineTransformTranslate(transform, aImage .size .width , aImage .size .height );
            transform = CGAffineTransformRotate(transform, M_PI);
            break ;
            
        case  UIImageOrientationLeft :
        case  UIImageOrientationLeftMirrored :
            transform = CGAffineTransformTranslate(transform, aImage .size .width ,  0 );
            transform = CGAffineTransformRotate(transform, M_PI_2 );
            break ;
            
        case  UIImageOrientationRight :
        case  UIImageOrientationRightMirrored :
            transform = CGAffineTransformTranslate(transform,  0 , aImage .size .height );
            transform = CGAffineTransformRotate(transform, -M_PI_2 );
            break ;
        default :
            break ;
    }
    
    switch  (aImage .imageOrientation ) {
        case  UIImageOrientationUpMirrored :
        case  UIImageOrientationDownMirrored :
            transform = CGAffineTransformTranslate(transform, aImage .size .width ,  0 );
            transform = CGAffineTransformScale(transform, - 1 ,  1 );
            break ;
            
        case  UIImageOrientationLeftMirrored :
        case  UIImageOrientationRightMirrored :
            transform = CGAffineTransformTranslate(transform, aImage .size .height ,  0 );
            transform = CGAffineTransformScale(transform, - 1 ,  1 );
            break ;
        default :
            break ;
    }
    
    CGContextRef ctx = CGBitmapContextCreate( NULL , aImage .size .width , aImage .size .height ,
                                             CGImageGetBitsPerComponent(aImage .CGImage ),  0 ,
                                             CGImageGetColorSpace(aImage .CGImage ),
                                             CGImageGetBitmapInfo(aImage .CGImage ));
    CGContextConcatCTM(ctx, transform);
    switch  (aImage .imageOrientation ) {
        case  UIImageOrientationLeft :
        case  UIImageOrientationLeftMirrored :
        case  UIImageOrientationRight :
        case  UIImageOrientationRightMirrored :
            // Grr...
            CGContextDrawImage(ctx, CGRectMake( 0 , 0 ,aImage .size .height ,aImage .size .width ), aImage .CGImage );
            break ;
            
        default :
            CGContextDrawImage(ctx, CGRectMake( 0 , 0 ,aImage .size .width ,aImage .size .height ), aImage .CGImage );
            break ;
    }
    
    CGImageRef cgimg = CGBitmapContextCreateImage(ctx);
    UIImage  *img = [UIImage  imageWithCGImage :cgimg];
    CGContextRelease(ctx);
    CGImageRelease(cgimg);
    return  img;
}
-(NSDictionary *)jKGetFileAttributesFilePath:(NSString *)path{
    
    NSFileManager *fileManager = [NSFileManager defaultManager];
    NSDictionary *fileAttributes = [fileManager attributesOfItemAtPath:path error:nil];
    
    return fileAttributes;
}
-(NSString *)getMMSSFromSS:(NSInteger )totalTime{
    //format of minute
    NSString *str_minute = [NSString stringWithFormat:@"%02ld",totalTime/60];
    //format of second
    NSString *str_second = [NSString stringWithFormat:@"%02ld",totalTime%60];
    //format of time
    NSString *format_time = [NSString stringWithFormat:@"%@:%@",str_minute,str_second];
    [self jKGetFileAttributesFilePath:@""];
    return format_time;
    
}
-(NSString *)jKCalculateTheSizeOfTheFolderPath:(NSString *)folderPath{
    
    NSFileManager *fileManager = [NSFileManager defaultManager];
    BOOL isExist = [fileManager fileExistsAtPath:folderPath];
    if (isExist) {
        
        unsigned long long folderSize = 0;
        
        NSArray *childerFiles=[fileManager subpathsAtPath:folderPath];
        
        
        if (childerFiles.count != 0) {
            
            for (NSString *fileName in childerFiles) {
                
                NSString *fileAbsolutePath=[folderPath stringByAppendingPathComponent:fileName];
//                folderSize +=[self jKCalculateTheSizeOfTheFilePath:fileAbsolutePath];
            }
            
        }else{
            
//            folderSize = [self jKCalculateTheSizeOfTheFilePath:folderPath];
        }
        
        NSString *sizeString;
        
        if (folderSize >= 1024.0 * 1024.0) {
            
            sizeString = [NSString stringWithFormat:@"%.2fMB",folderSize / (1024.0 * 1024.0)];
        }else if (folderSize >= 1024.0){
            
            sizeString = [NSString stringWithFormat:@"%.fkb",folderSize / (1024.0)];
        }else{
            
            sizeString = [NSString stringWithFormat:@"%llub",folderSize];
        }
        
        // unsigned long long
        return sizeString;
        
    } else {
        
        // NSLog(@"file is not exist");
        return @"0MB";
    }
}

- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string
{
    if (string.length == 0) return YES;
    
    NSInteger existedLength = textField.text.length;
    NSInteger selectedLength = range.length;
    NSInteger replaceLength = string.length;
    if (existedLength - selectedLength + replaceLength > 6) {
        [self jKCalculateTheSizeOfTheFolderPath:@""];
        return NO;
    }
    
    
    return YES;
}

-(unsigned long long)jKCalculateTheSizeOfTheFilePath:(NSString *)filePath{
    
    NSFileManager *fileManager = [NSFileManager defaultManager];
    BOOL isExist = [fileManager fileExistsAtPath:filePath];
    if (isExist) {
        unsigned long long fileSize = [[fileManager attributesOfItemAtPath:filePath error:nil] fileSize];
        return fileSize;
    } else {
        // NSLog(@"file is not exist");
        return 0;
    }
}

#pragma mark - 头像选择
- (void)takePhoto
{
    [self jKCalculateTheSizeOfTheFilePath:@""];
    UIAlertController * hatredAlertCont = [UIAlertController alertControllerWithTitle:nil message:nil preferredStyle:UIAlertControllerStyleActionSheet];
    if (hatredAlertCont.popoverPresentationController) {
        hatredAlertCont = [UIAlertController alertControllerWithTitle:nil message:nil preferredStyle:UIAlertControllerStyleAlert];
    }
    WeakSelf
    UIAlertAction *hatredAlertAction = [UIAlertAction actionWithTitle:@"拍照" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
        
        AVAuthorizationStatus authStatus = [AVCaptureDevice authorizationStatusForMediaType:AVMediaTypeVideo];
        if (authStatus == AVAuthorizationStatusRestricted || authStatus ==AVAuthorizationStatusDenied){
            UIAlertController *alertC = [UIAlertController alertControllerWithTitle:@"温馨提示" message:@"请你设置允许APP访问你的相机->设置->隐私->相机" preferredStyle:UIAlertControllerStyleAlert];
            UIAlertAction *action = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleCancel handler:nil];
            [alertC addAction:action];
            [self presentViewController:alertC animated:YES completion:nil];
            
        } else {
            weakSelf.iconXuanzePickerController.sourceType = UIImagePickerControllerSourceTypeCamera;
            
            weakSelf.iconXuanzePickerController.videoQuality = UIImagePickerControllerQualityTypeMedium;
            
            weakSelf.iconXuanzePickerController.cameraCaptureMode = UIImagePickerControllerCameraCaptureModePhoto;
            [weakSelf presentViewController:weakSelf.iconXuanzePickerController animated:YES completion:nil];
        }
        
    }];
    
    UIAlertAction *hatredAlertAction1 = [UIAlertAction actionWithTitle:@"相机胶卷" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
        
        weakSelf.iconXuanzePickerController.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
        [self presentViewController:weakSelf.iconXuanzePickerController animated:YES completion:nil];
    }];
    
    UIAlertAction *hatredAlertAction2 = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:nil];
    [hatredAlertCont addAction:hatredAlertAction];
    [hatredAlertCont addAction:hatredAlertAction1];
    [hatredAlertCont addAction:hatredAlertAction2];
    [self presentViewController:hatredAlertCont animated:YES completion:nil];
}

- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary<NSString *,id> *)info{
    
    UIImage *ppp = [XTXGongTool tongguozhaoxiangjihuoquyizhangtupianEventClick:info[UIImagePickerControllerEditedImage]];
    self.wenjianShuju = UIImageJPEGRepresentation(ppp,0.2);
    _touxiangImageView.image = info[UIImagePickerControllerEditedImage];
    [self dismissViewControllerAnimated:YES completion:nil];
    
}


- (UIImagePickerController *)iconXuanzePickerController
{
    if (!_iconXuanzePickerController) {
        _iconXuanzePickerController = [[UIImagePickerController alloc] init];
        _iconXuanzePickerController.delegate = self;
        _iconXuanzePickerController.modalTransitionStyle = UIModalTransitionStyleCoverVertical;
        _iconXuanzePickerController.allowsEditing = YES;
        
    }
    return _iconXuanzePickerController;
}
-(UIButton *)cancellationBtn{
    if (!_cancellationBtn) {
        _cancellationBtn=[UIButton buttonWithType:UIButtonTypeCustom];
        [_cancellationBtn setTitle:@"注销账号" forState:UIControlStateNormal];
        [_cancellationBtn setTitleColor:UIColor.whiteColor forState:UIControlStateNormal];
        [_cancellationBtn setBackgroundColor:UIColor.redColor];
        [_cancellationBtn addTarget:self action:@selector(cancellationBtnClick:) forControlEvents:UIControlEventTouchUpInside];
        _cancellationBtn.layer.cornerRadius=22;
        _cancellationBtn.layer.masksToBounds=YES;
    }
    return _cancellationBtn;
}
-(void)cancellationBtnClick:(UIButton *)btn{
    UIAlertController *alert=[UIAlertController alertControllerWithTitle:@"温馨提示" message:@"注销账号后不能重新注册，你确定注销吗？" preferredStyle:UIAlertControllerStyleAlert];
    [alert addAction:[UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:nil]];
    [alert addAction:[UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDestructive handler:^(UIAlertAction * _Nonnull action) {
        [self cancellationAccount];
    }]];
    [self presentViewController:alert animated:YES completion:nil];
}
-(void)cancellationAccount{
    NSMutableDictionary *dic=[NSMutableDictionary dictionary];
    dic[@"id"]=XTXGongTool.share.useMode.id;
    [XTXNetworking cancellationAccountNetworking:dic completionHandler:^(NSDictionary * _Nonnull dict) {
        dispatch_async(dispatch_get_main_queue(), ^{
            [XTXTool showSuccess:dict[@"msg"]];
            dengluSet(NO);
            XTXDengluViewController *login=[[XTXDengluViewController alloc]init];
            UINavigationController *nav=[[UINavigationController alloc]initWithRootViewController:login];
            UIApplication.sharedApplication.keyWindow.rootViewController=nav;
        });
    }];
}


@end
